package xyz.hubery.event;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import xyz.hubery.dto.CreateKLineDto;
import xyz.hubery.dto.MarketDto;
import xyz.hubery.feign.MarketServiceFeign;
import xyz.hubery.service.TradeKlineService;

import java.math.BigDecimal;
import java.util.List;

/**
 * 行情数据的 K 线
 */
@Component
@Slf4j
public class TradeKLineEvent implements Event {

    @Autowired
    private MarketServiceFeign marketServiceFeign;

    @Override
    public void handle() {
        List<MarketDto> markets = marketServiceFeign.findAllMarkets();
        if(CollectionUtils.isEmpty(markets)) {
            return;
        }
        for (MarketDto market : markets) {
            CreateKLineDto kLineDto = new CreateKLineDto();
            kLineDto.setSymbol(market.getSymbol());
            kLineDto.setPrice(market.getOpenPrice());
            kLineDto.setVolume(BigDecimal.ZERO);
            TradeKlineService.addData(kLineDto);
        }
    }
}